A set of classes for using WASTE with the Think Class Libraries
by Dan Crevier
Introduction
This is a set of classes I've written to use Marco Piovanelli's text edit replacement WASTE with the Think Class Libraries. It only works with versions 2.0.3 or newer of TCL. It has currently been tested with WASTE 1.0a4.
I wanted to use WASTE in one of my applications mainly for the ability to use more than 32K of text, and to use inline input for Japanese. The classes are not well tested at this point, and probably contain many bugs. I am releasing these classes as public domain, so you are free to use them as you see fit. Remember to give Marco Piovanelli credit if you use WASTE, and you can give me some credit if you feel like it. If you use these classes, I'd be very interested in any bug reports (especially if they include fixes) and any improvements anyone makes. I'd like to thank Marco Piovanelli both for making WASTE available and for his help in figuring out how to get it to work with the class libraries.
There are 3 classes included. They are:
CWASTEText - a subclass of CAbstractText which is much like
CStyleText
CWASTEDlgText - a subclass of CWASTEText which is a bit like
CDialogText, but without all of the validation features. It
has a border, broadcasts changes when the text changes,
and passes return, enter and escape to the supervisor.
CTSMSwitchboard - a subclass of CSwitchboard which deals
with Text Service Manager events.
I also made some slight modifications to the WASTE header files. Hopefully Marco will be able to include these in future versions of WASTE.
I've also included a slightly modified version of TinyEdit, called WASTEEdit, which uses WASTE as a simple example program.
Adding WASTE Support
If you wish to use these classes in your application, you need to add the following to your application class:
Near the top:
#include "WASTE.h"
#ifndef __SCRIPT__
#include <Script.h>
#endif
#include "CTSMSwitchboard.h"
static Boolean TSMAvailable(void);
short gUsingTSM = false;
In the constructor:
gUsingTSM = TSMAvailable();
if (gUsingTSM) gUsingTSM = (InitTSMAwareApplication()==noErr);
See WASTEEdit for an example. Most of this stuff is to provide inline input. Even if you don't use Japanese on your system, I recommend leaving the support there for those that do have inline input.
You need to add CTSMSwitchboard.cpp, CWASTEText.cpp, CWASTEDlgText.cpp, and WASTE.o to your project.
CWASTEText
CWASTEText is a subclass of CAbstractText, and is very similar to CStyleText. In addition, I have added the following functions:
StopInlineSession() - Stops the current inline input session
and validates the text.
InsertWithStyle() - Lets you insert some text and it's
corresponding StScrpHandle information all in one step.
Clear() - clears the text in the class without any excess
highlighting.
CopyRangeWithStyle() - gets the text and styles for a range
of text all in one step.
There are some problems with CWASTEText. A lot of the functions haven't been tested well or at all. Also, I should add some functions for easy color support. TCL isn't good at supporting text without fixed height lines. SetWholeLines(true) doesn't work well. I set the scrolling steps to 12 vertically and 4 horizontally fow when it's in a scroll pane. Something more intelligent could probably be done.
Note: I haven't made an EditTask class for WASTE.
CWASTEDlgText
CWASTEDlgText was made to provide some of the funcitonality of CDialogText. A dialogTextChanged message is broadcast when the text is changed. This wasn't easy for text being entered with inline input, but I think I have it working with a WEPostUpdate routine. It may be broadcasting the message more often than it needs to, but that's ok with me.
It also has a border, just like CDialogText, and passes tab, return, enter, and escape to the supervisor instead of typing them.
I added the GetTextString() method to get the text into a Str255.
CTSMSwitchboard
This is a subclass of CSwitchboard which handles Text Service Manager events. I don't think it is calling TSMCursor as much as it should be though...
WASTEEdit
WASTEEdit is a slightly modified version of TinyEdit to get it to work with WASTE. I tried to do the minimum modifications necessary to get it to work, so I haven't added any functionality. With a little work, I think a nice application could be made out of it. Right now, it's almost 10 times as big as WASTE Demo, and doesn't do quite as much. It would be really great if someone wanted to add all the scripting support to it, so we would have a nice replacement for the Scriptable Text Editor.